package org.example.design.designmode.combination.filedemo;

import java.util.ArrayList;
import java.util.List;

public class Folder extends  Direcotry {
    //这里需要思考个问题？
    // 1、为啥list里面放Direcotry 而不是放File或Folder
    // 假设1、成立如果对整个业务结构进行扩展、再添加修改、删除、查看详细信息的时候那这个list的局限性就出来了
    //需要我们不断地处理这个list层级结构关系、所以这里直接存放Direcotry顶层抽象
    //不管如何扩展只需要在Direcotry中增加、删除接口
    private List<Direcotry> items ;

    private int levle;

    public Folder(String name,int levle) {
        super(name);
        this.levle=levle;
        items = new ArrayList<>();

    }

    public void removeChild(Direcotry c) {
        items.remove(c);
    }


    public void addChild(Direcotry c) {
        items.add(c);
    }

    public Direcotry get(int index) {
        return items.get(index);
    }

    public void list() {

        for (Direcotry cc:items) {
            System.out.println(cc.name);
        }

    }
    @Override
    public void show() {
        System.out.println(this.name);
        for (Direcotry cc:items) {
            if(this.levle>0){
                for (int j = 0; j < this.levle; j++) {
                    System.out.print("     ");
                }
                for (int s = 0; s < this.levle; s++) {
                    if(s==0){System.out.print("+");}
                    System.out.print("-");
                }
            }

            cc.show();
        }
    }
}
